/*
 * Session.h
 *
 *  Created on: 07.10.2012
 *      Author: Sven
 */

#ifndef SESSION_H_
#define SESSION_H_

class CSession
{
public:
	CSession() { m_player = 0; memset(&m_addr, 0, sizeof(sockaddr_in)); };
	CSession(CSession* session) { m_player = session->getplayer(); memcpy(&m_addr, session->getaddr(), sizeof(sockaddr)); }
	~CSession() { if(m_player) delete m_player; };

	void init(sockaddr_in* addr);

	sockaddr_in* 	getaddr() { return &m_addr; }
	unsigned int 	getip() { return (unsigned int)m_addr.sin_addr.s_addr; }
	CPlayer*		getplayer() { return m_player; }

	void			setplayer(CPlayer* player) { m_player = player; }

	static map<unsigned int, CSession*>	m_sessions;
private:
	sockaddr_in m_addr;

	CPlayer* 	m_player;
};

#endif /* SESSION_H_ */
